<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="../base.jsp" %>
	<style>
	.content-wrapper{margin-left: 0px}
	</style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">
		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>视图管理<small>视图管理</small></h1>
				<ol class="breadcrumb">
					<li><a href="javascript:;"><i class="fa fa-dashboard"></i> 首页</a></li>
					<li class="active">视图管理</li>
				</ol>
			</section>
			<!-- Main content -->
			<section class="content">
				<div class="row">
					<div class="col-md-12">
			          <div class="box">
			            <div class="box-header with-border">
			              <h3 class="box-title">
			              	<div class="box-tools">
				              <a class="btn btn-primary" href="${url }analysis/view/toAdd">添加</a>
				            </div>
				           </h3>
			            </div>
			            <!-- /.box-header -->
			            <div class="box-body">
			              <table class="table table-bordered">
			                <tr>
			                  <th>视图名称</th>
			                  <th>排列方式</th>
			                  <th>状态</th>
			                  <th>操作</th>
			                </tr>
			                <c:forEach items="${list }" var="list">
			                <tr>
			                  <td>${list.viewname }</td>
			                  <td>${list.viewrows }行&nbsp;&nbsp;${list.viewcols }列</td>
			                  <td>
			                  	<c:if test="${list.viewflag == 0}">
				                    <span class="badge bg-green">启用</span>
			                  	</c:if>
			                  	<c:if test="${list.viewflag == 1}">
				                    <span class="badge bg-red">禁用</span>
			                  	</c:if>
			                  </td>
			                  <td>
			                  	<c:if test="${list.viewflag == 1}">
				                    <a class="btn btn-sm btn-primary" onclick="changeStatus('${list.viewid}','1')">启用</a>
			                  	</c:if>
			                  	<c:if test="${list.viewflag == 0}"> 
			                  		<a class="btn btn-sm btn-success" onclick="viewportal('${list.viewid}',${list.viewrows },${list.viewcols });">预览</a>
			                  		<a class="btn btn-sm btn-primary" onclick="getViewURL('${list.viewid}',${list.viewrows },${list.viewcols })">URL</a>
				                    <a class="btn btn-sm btn-warning" onclick="changeStatus('${list.viewid}','0')">禁用</a>
			                  	</c:if>
			                  	<a class="btn btn-sm btn-danger" onclick="deleteView('${list.viewid}')">删除</a>
			                  </td>
			                </tr>
			                </c:forEach>
			              </table>
			            </div>
			            <!-- /.box-body -->
			            <div class="box-footer clearfix">
			              <ul class="pagination pagination-sm no-margin pull-right">
			              <!-- 
			                <li><a href="#">&laquo;</a></li>
			                <li><a href="#">1</a></li>
			                <li><a href="#">2</a></li>
			                <li><a href="#">3</a></li>
			                <li><a href="#">&raquo;</a></li>
			                -->
			              </ul>
			            </div>
			          </div>
				</div>
			</section>
		</div>
	</div>
<script type="text/javascript">
	function changeStatus(id,status){
		$.post(path+"analysis/view/changeStatus",{id:id,status:status},function(data){
			if(data.result = "true"){
				layer.alert("操作成功",{closeBtn:0},function(){
					location.href = path+"analysis/view/viewlist";
				});
			}else{
				layer.alert("操作失败");
			}
		});
	}
	function deleteView(id){
		$.post(path+"analysis/view/delview",{id:id},function(data){
			if(data.result = "true"){
				layer.alert("操作成功",{closeBtn:0},function(){
					location.href = path+"analysis/view/viewlist";
				});
			}else{
				layer.alert("操作失败");
			}
		});
	}
	
	function getViewURL(viewid,viewrows,viewcols){
		//iframe层
		layer.open({
		  type: 1,
		  title: '获取url',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['50%', '100px'],
		  content: '<div>${fullURL }analysis/view/viewportal?viewrows='+viewrows+'&viewcols='+viewcols+'&id='+viewid+'</div>'
		});
	}
	
	function viewportal(id,viewrows,viewcols){
		//iframe层
		layer.open({
		  type: 2,
		  title: '预览图表',
		  shadeClose: true,
		  shade: 0.8,
		  area: ['100%', '100%'],
		  maxmin:true,
		  content: '${url }analysis/view/viewportal?id='+id+'&viewrows='+viewrows+'&viewcols='+viewcols
		}); 
	}
</script>
</body>
</html>